package graphics.tools;
import graphics.system.Color;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;

import org.lwjgl.BufferUtils;

import tools.Point;
/**
 * converter tools for transfering data to OpenGL Do NOT use for not OpenGL stuff. Buffers are rewinded in some cases!
 * 
 * @author jonathan
 * 
 */
public final class Tools {
	public static IntBuffer arrayToIntBuffer(int array[]) {
		IntBuffer b = BufferUtils.createIntBuffer(array.length);
		b.put(array);// .rewind();
		b.position(0);
		return b;
	}
	public static FloatBuffer arrayToFloatBuffer(float array[]) {
		FloatBuffer b = BufferUtils.createFloatBuffer(array.length);
		b.put(array).rewind();
		return b;
	}
	public static FloatBuffer arrayPointToFloatBuffer(Point array[]) {
		float vertdata[] = new float[array.length * 2];
		for (int i = 0; i < array.length; i++) {
			vertdata[i * 2] = array[i].x;
			vertdata[i * 2 + 1] = array[i].y;
		}
		FloatBuffer b = BufferUtils.createFloatBuffer(vertdata.length);
		b.put(vertdata).rewind();
		return b;
	}
	public static FloatBuffer arrayColorToFloatBuffer(Color cols[]) {
		float cdata[] = new float[cols.length * 4];
		for (int i = 0; i < cols.length; i++) {
			cdata[i * 4] = cols[i].r;
			cdata[i * 4 + 1] = cols[i].g;
			cdata[i * 4 + 2] = cols[i].b;
			cdata[i * 4 + 3] = cols[i].a;
		}
		FloatBuffer b = BufferUtils.createFloatBuffer(cdata.length);
		b.put(cdata).rewind();
		return b;
	}
}
